package partner_user

import (
	"gitee.com/theegg/go-brick/app/model/user/user_account_flow_reports"
	"gitee.com/theegg/go-brick/app/model/user/user_accounts"
	"gitee.com/theegg/go-brick/app/model/user/users"
	"gitee.com/theegg/go-brick/app/service/app"
	"gitee.com/theegg/go-brick/app/service/help/cstruct"
	"github.com/gin-gonic/gin"
	"strconv"
)

// 获取 账户流转 列表
func GetAccountFlowReportList(c *gin.Context) {
	// 检验参数
	var validaParams user_account_flow_reports.AccountFlowReportQueryParams
	if err := c.ShouldBind(&validaParams); err != nil {
		app.NewResponse(c).JsonReturn(false, "bind-json-"+err.Error(), nil)
		return
	}

	// 查询数据
	data, err := user_account_flow_reports.GetDataList(cstruct.StructToMap(validaParams))
	if err != nil {
		app.NewResponse(c).JsonReturn(false, err.Error(), data)
		return
	}

	data["flow_type_options"] = user_accounts.AccountFlowType

	app.NewResponse(c).JsonReturn(true, "获取数据成功", data)
	return
}

// 详情
func GetAccountFlowReportDetail(c *gin.Context) {
	app.NewResponse(c).JsonReturn(true, "获取数据成功", nil)
	return
}

/** =========================== 辅助查询 ============================ **/
// @title getTargetFlowReportFromParams
// @description 内置方法　通过参数id获取目标对象, 验证当前 登陆用户 是否可以操作 目标用户
func getTargetFlowReportFromParams(c *gin.Context) (*users.Users, error) {
	id := c.PostForm("id")
	if id == "" {
		return nil, app.NewError("对不起, 管理员ID不能为空")
	}

	// ID 转换格式
	int64Id, errParse := strconv.ParseInt(id, 10, 64)
	if errParse != nil {
		return nil, app.NewError("对不起, 目标用户ID格式不正确")
	}

	// 获取用户
	targetUser, errTarget := users.GetItemById(int64Id)
	if errTarget != nil {
		return nil, app.NewError(errTarget)
	}

	return targetUser, nil
}
